import 'whatwg-fetch'
import 'es6-promise'

const obj2params=(obj)=>{
    var result = '';
    var item;
    for (item in obj) {
        result += '&' + item + '=' + encodeURIComponent(obj[item]);
    }

    if (result) {
        result = result.slice(1);
    }

    return result;
}
//get请求传入参数请求地址url
export const get=(url)=>{
    var result=fetch(url,{
        credentials:'include',
        headers:{
            'Accept':'application/json, text/plain, */*'
        }
    });
}
//post求情传入参数 请求地址url 和数据paramsObj 其中和数据paramsObj格式为对象{a:b,c:d}
export const post=(url,paramsObj)=>{
 var result = fetch(url, {
        method: 'POST',
        credentials: 'include',
        headers: {
            'Accept': 'application/json, text/plain, */*',
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: obj2params(paramsObj)
    });

    return result;
}